<div id="offline-check-view">
  <div class="pageheader">
    <h2><i class="fa fa-home"></i>线下入住{{contractData?('(合同号：'+contractData.uuid+')'):''}}</h2>
    <div class="al-header-right" ng-if="contractData">
      <button type="button" class="btn btn-danger" ng-if="contractData.status<8"
              ng-confirm-click="确认取消办理本入住吗？"
              ng-click="doCancel()">取消
      </button>
      <button type="button" class="btn btn-warning" ng-if="contractData.status==8"
              ng-click="doCancel()">返回
      </button>
    </div>
  </div>
  <div class="page">
    <ng-form class="form-horizontal" ng-if="earnest">
      <div class="form-group">
        <h4 class="text-center">预订信息</h4>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">预订公寓</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{earnest.apartmentName}}</div>
        </div>
        <label class="control-label col-sm-2">预订楼栋</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{earnest.buildingName}}</div>
        </div>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">预订房间号</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{earnest.houseNo}}</div>
        </div>
        <label class="control-label col-sm-2">计划入住时间</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{earnest.startTime|dateTransfer:'YYYY-MM-DD'}}</div>
        </div>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">预订手机号</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{earnest.customerPhone}}</div>
        </div>
        <label class="control-label col-sm-2">预订姓名</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{earnest.customerName}}</div>
        </div>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">定金金额</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{earnest.money}}</div>
        </div>
        <label class="control-label col-sm-2">实收金额</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{earnest.payMoney}}</div>
        </div>
      </div>
    </ng-form>
    <ng-form name="contractForm" class="form-horizontal">
      <div class="form-group">
        <h4 class="text-center">房间信息</h4>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">公寓</label>
        <div class="col-sm-3" ng-if="apartmentList.length>0">
          <select ng-if="$root.storeAu==undefined"
                  ng-model="contractNew.apartmentId" class="form-control"
                  ng-change="loadBuilding()"
                  ng-disabled="contractNew.created"
                  ng-options="option.id as option.name for option in apartmentList"></select>
          <div class="form-control info-text"
               ng-if="$root.storeAu!=undefined">{{$root.storeAu|constantTransfer:apartmentList:'id'}}</div>
        </div>
        <label class="control-label col-sm-2">楼栋</label>
        <div class="col-sm-3">
          <select ng-model="contractNew.buildingId" ng-readonly="contractNew.created"
                  class="form-control" ng-change="loadFloor()"
                  ng-options="option.id as option.name for option in buildingList"></select>
        </div>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">楼层</label>
        <div class="col-sm-3">
          <select ng-model="contractNew.floor" ng-readonly="contractNew.created || contractNew.buildingId==undefined"
                  class="form-control" ng-change="loadHouse()"
                  ng-options="option.id as option.name for option in floorList"></select>
        </div>
        <label class="control-label col-sm-2">房间号</label>
        <div class="col-sm-3">
          <select ng-model="contractNew.houseId" ng-readonly="contractNew.created || contractNew.floor==undefined"
                  class="form-control" ng-change="pickHouse()"
                  ng-options="option.id as option.houseNo for option in houseList"></select>
        </div>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">租房方式</label>
        <div class="col-sm-3">
          <select ng-model="contractNew.payWay" ng-readonly="contractNew.created || houseInfo==undefined"
                  class="form-control" ng-change="getHousePrice()"
                  ng-options="option.value as option.name for option in payWayList"></select>
        </div>
        <label class="control-label col-sm-2">租期</label>
        <div class="col-sm-3">
          <select ng-model="contractNew.lease" ng-readonly="contractNew.created || houseInfo==undefined"
                  class="form-control" ng-change="getHousePrice()"
                  ng-options="option.value as option.name for option in leaseList"></select>
        </div>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">合同开始日期<span class="attr-need">*</span></label>
        <div class="col-sm-3">
          <div class="input-group">
            <input class="form-control" type="text" uib-datepicker-popup="yyyy-MM-dd" readonly
                   ng-model="contractNew.leaseStart" is-open="enterStart" maxlength="10"
                   close-text="关闭" current-text="今天" clear-text="清空" required
                   ng-change="getHousePrice()"
                   placeholder=""/>
            <span class="input-group-btn">
                <button type="button" class="btn btn-default" ng-click="enterStart=true">
                  <i class="glyphicon glyphicon-calendar"></i>
                </button>
              </span>
          </div>
        </div>

        <!--<label class="control-label col-sm-2">合同签署时间</label>-->
        <!--<div class="col-sm-3">-->
        <!--<input type="text" class="form-control" ng-model="contractNew.signTime">-->
        <!--</div>-->
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">月租金</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{housePrice==undefined?'--':housePrice.rental}}</div>
        </div>
        <label class="control-label col-sm-2">押金</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{housePrice==undefined?'--':housePrice.deposit}}</div>
        </div>
      </div>
      <div class="form-group" ng-if="housePrice && housePrice.activityList && housePrice.activityList.length>0">
        <label class="control-label col-sm-2 col-sm-offset-1">优惠活动</label>
        <div class="col-sm-9">
          <select ng-model="contractNew.activityId" class="form-control"
                  ng-readonly="contractNew.created"
                  ng-options="option.id as option.ruleName for option in housePrice.activityList"></select>
        </div>
      </div>
    </ng-form>
    <ng-form name="personForm" class="form-horizontal form-validation">
      <div class="form-group">
        <h4 class="text-center">租客信息</h4>
      </div>
      <div class="form-group">
        <div class="col-sm-6">
          <div class="form-group">
            <label class="control-label col-sm-4 col-sm-offset-2">租客手机号<span class="attr-need">*</span></label>
            <div class="col-sm-6">
              <input type="text" class="form-control" ng-change="fetchUser()"
                     ng-readonly="contractNew.created || earnest" required
                     ng-pattern="$root.phoneVd"
                     ng-model="person.customerPhone">
            </div>
          </div>
          <div class="form-group">
            <label class="control-label col-sm-4 col-sm-offset-2">租客名称<span class="attr-need">*</span></label>
            <div class="col-sm-6">
              <input type="text" class="form-control"
                     ng-readonly="contractNew.created" required
                     ng-model="person.customerName">
            </div>
          </div>
          <div class="form-group">
            <label class="control-label col-sm-4 col-sm-offset-2">身份证<span class="attr-need">*</span></label>
            <div class="col-sm-6">
              <input type="text" class="form-control" required
                     ng-pattern="$root.idCardVd"
                     ng-readonly="contractNew.created"
                     ng-model="person.customerCard">
            </div>
          </div>
          <div class="form-group">
            <label class="control-label col-sm-4 col-sm-offset-2">性别</label>
            <div class="col-sm-6">
              <nobr>
                <label class="ui-radio" ng-repeat="option in sexList">
                  <input name="status" ng-value="option.value" ng-disabled="contractNew.created"
                         type="radio" ng-model="person.sex">
                  <span>{{option.name}}</span>
                </label>
              </nobr>
            </div>
          </div>
          <div class="form-group">
            <label class="control-label col-sm-4 col-sm-offset-2">住客人数</label>
            <div class="col-sm-6">
              <div class="input-group">
                <input type="number" class="form-control" readonly ng-model="cotenant.length" maxlength="4">
                <span class="input-group-addon" ng-click="offlineCotenant()">{{contractData?'查看':'编辑'}}</span>
              </div>
            </div>
          </div>
        </div>
        <div class="col-sm-6">
          <div class="form-group" style="margin-bottom: 10px;">
            <label class="control-label col-sm-4 ">身份证正面</label>
            <div class="col-sm-6 id-card-container">
              <img ng-src="{{person.idcardFront?person.idcardFront:'images/id_card_front.jpg'}}"
                   ng-click="uploadIDCFront()">
              <input id="off-idcard-front" style="display: none" type="file">
            </div>
          </div>
          <div class="form-group">
            <label class="control-label col-sm-4">身份证反面</label>
            <div class="col-sm-6 id-card-container">
              <img ng-src="{{person.idcardBack?person.idcardBack:'images/id_card_back.jpg'}}"
                   ng-click="uploadIDCBack()">
              <input id="off-idcard-back" style="display: none" type="file">
            </div>
          </div>
        </div>

      </div>
      <div class="form-group">
        <div class="col-sm-12 text-center">
          <button class="btn btn-primary mr-15" ng-if="contractNew.created"
                  ng-click="editContract()">合同编辑
          </button>
          <button class="btn btn-primary mr-15" ng-if="!contractNew.created"
                  ng-disabled="contractNew.creating || contractForm.$invalid || personForm.$invalid"
                  ng-click="createContract()">生成合同
          </button>
          <button class="btn btn-warning mr-15" ng-if="contractNew.created"
                  ng-click="printContract()">合同打印
          </button>
        </div>
      </div>
    </ng-form>
    <contract-payment-form ng-if="contractData && billId"
                           bill-id="billId" contract-data="contractData"></contract-payment-form>
    <ng-form class="form-horizontal form-validation" ng-if="contractData">
      <div class="form-group" ng-if="contractData.status==4 || contractData.status==8">
        <h4 class="text-center">入住信息</h4>
      </div>
      <div class="form-group" ng-if="contractData.status==4 || contractData.status==8">
        <label class="control-label col-sm-2 col-sm-offset-1">业务员<span class="attr-need">*</span></label>
        <div class="col-sm-3">
          <input class="form-control" type="text" required ng-readonly="contractData.status==8"
                 ng-model="checkIn.receptionist">
        </div>
        <label class="control-label col-sm-2">渠道</label>
        <div class="col-sm-3">
          <select ng-model="checkIn.buzType" class="form-control" ng-readonly="contractData.status==8"
                  ng-options="option.value as option.name for option in channelTypeList"></select>
        </div>
      </div>
      <div class="form-group" ng-if="contractData.status==4 || contractData.status==8">
        <label class="control-label col-sm-2 col-sm-offset-1">邀请码</label>
        <div class="col-sm-3">
          <input class="form-control" name="receptionist" ng-readonly="contractData.status==8"
                 type="text" ng-model="checkIn.inviteCode">
        </div>
      </div>
      <div class="form-group" ng-if="contractData.status==4 || contractData.status==8">
        <label class="control-label col-sm-2 col-sm-offset-1">备注</label>
        <div class="col-sm-8">
          <textarea class="form-control" ng-readonly="contractData.status==8"
                    placeholder="填写备注信息"
                    ng-model="checkIn.contractPicture"></textarea>
        </div>
      </div>
      <div class="form-group">
        <div class="col-sm-4"></div>
        <div class="col-sm-4 text-center">
          <button class="btn btn-success" ng-if="contractData.status==4"
                  ng-disabled="!checkIn.receptionist"
                  ng-click="offlineCheckIn()">快捷入住
          </button>
        </div>
        <div class="col-sm-4"></div>
      </div>
    </ng-form>
  </div>
</div>